package com.demo.dao.mapper;

import com.demo.model.OrderExpand;
import com.demo.model.Product;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

public class OrderExpandMapper {
    public String insert(OrderExpand orderExpand) {
        return "insert into `Order_expand` (productId, price, number,orderId) values (#{productId},#{price},#{number},#{orderId})";
    }

    public String delete(Integer id) {
        BEGIN();
        DELETE_FROM("`order_expand`");
        WHERE("id=#{id}");
        return SQL();
    }

    public String update(OrderExpand orderExpand) {
        BEGIN();
        UPDATE("`order_expand`");
        if (orderExpand.getProductId() != null && orderExpand.getProductId() > 0) {
            SET("productId=#{productId}");
        }
        if (orderExpand.getNumber() != null && orderExpand.getNumber() > 0) {
            SET("number=#{number}");
        }
        if (orderExpand.getPrice() != null && orderExpand.getPrice() > 0) {
            SET("price=#{price}");
        }
        if (orderExpand.getOrderId() != null && orderExpand.getOrderId() > 0) {
            SET("orderId=#{orderId}");
        }
        WHERE("id=#{id}");
        String sql = SQL();
        System.out.println(sql);
        return sql;
    }

    public String select(Integer productId) {
        if (productId == null) {
            return "select * from `Order_expand` order by id desc";
        } else {
            return "select * from `Order_expand` where productId=#{productId} order by id desc";
        }
    }

    public String selectOne(Integer id) {
        return "select * from `Order_expand` where id=#{id}";
    }


    public String selectOneByOrderId(Integer orderId) {
        return "select * from `Order_expand` where orderId=#{orderId}";
    }
}
